package com.wl.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

@WebFilter(value="/app",
        initParams = {@WebInitParam(name="age",value="20"),
                      @WebInitParam(name="sex",value="male")})
public class AppFilter2 implements Filter {

    FilterConfig filterConfig;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter2 init....");
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        System.out.println("filter2 dofilter....");
        System.out.println(filterConfig.getInitParameter("age"));
        System.out.println(filterConfig.getInitParameter("sex"));
        chain.doFilter(req,resp);
    }

    @Override
    public void destroy() {
        System.out.println("filter2 destroy...");
    }
}
